/**
 * Created by Elsa on 2017/9/5.
 */
layui.define(['jquery', 'layer','paging', 'code','form','element','upload'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        upload = layui.upload,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var docnum = getQueryString("inspnum");

    paging.init({
        url: contextPath + "/project/const/doc/" + docnum, //地址
        elem: '#con', //内容容器
        type: 'GET',
        params: { //发送到服务端的参数

        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调
        },
    });

    $("body").on("click",".moress",function(){
        var uploadtime = $(this).data('id');
        tampdata = $(this).data('id');

        $.ajax({
            type:"GET",
            url:contextPath+"/project/const/doc/info",
            data: {"docnum": docnum, "uploadtime": uploadtime},
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function (data) {
                $.get('ConstDetailsDoc.html', null, function(ConstDetailsDoc) {
                    layer.open({
                        type: 1,
                        title: '文档详情',
                        content: ConstDetailsDoc,
                        area: ['auto', '600px'],
                        maxmin: false,
                        success:function (layero,index) {
                            layero.find("#closex").on("click",function () {
                                layer.closeAll();
                            });
                            layero.find("#close").on("click",function () {
                                layer.closeAll();
                            });

                            if(data.doc1){
                                var doc1name = data.doc1.substring(data.doc1.lastIndexOf("/")+1,data.doc1.lastIndexOf("."));
                                $('#doclist1').attr("href",contextPath+'/download?file='+data.doc1);
                                $('#doclist1name').html("&ensp;"+doc1name);
                                $('#doclist1').css("visibility",'visible');
                            }
                            if(data.doc2){
                                var doc2name = data.doc2.substring(data.doc2.lastIndexOf("/")+1,data.doc2.lastIndexOf("."));
                                $('#doclist2').attr("href",contextPath+'/download?file='+data.doc2);
                                $('#doclist2name').html("&ensp;"+doc2name);
                                $('#doclist2').css("visibility",'visible');
                            }
                            if(data.doc3){
                                var doc3name = data.doc3.substring(data.doc3.lastIndexOf("/")+1,data.doc3.lastIndexOf("."));
                                $('#doclist3').attr("href",contextPath+'/download?file='+data.doc3);
                                $('#doclist3name').html("&emsp;"+doc3name);
                                $('#doclist3').css("visibility",'visible');
                            }
                            if(data.doc4){
                                var doc4name = data.doc4.substring(data.doc4.lastIndexOf("/")+1,data.doc4.lastIndexOf("."));
                                $('#doclist4').attr("href",contextPath+'/download?file='+data.doc4);
                                $('#doclist4name').html("&ensp;"+doc4name);
                                $('#doclist4').css("visibility",'visible');
                            }
                            if(data.doc5){
                                var doc5name = data.doc5.substring(data.doc5.lastIndexOf("/")+1,data.doc5.lastIndexOf("."));
                                $('#doclist5').attr("href",contextPath+'/download?file='+data.doc5);
                                $('#doclist5name').html("&ensp;"+doc5name);
                                $('#doclist5').css("visibility",'visible');
                            }
                            if(data.doc6){
                                var doc6name = data.doc6.substring(data.doc6.lastIndexOf("/")+1,data.doc6.lastIndexOf("."));
                                $('#doclist6').attr("href",contextPath+'/download?file='+data.doc6);
                                $('#doclist6name').html("&ensp;"+doc6name);
                                $('#doclist6').css("visibility",'visible');
                            }
                            if(data.doc7){
                                var doc7name = data.doc7.substring(data.doc7.lastIndexOf("/")+1,data.doc7.lastIndexOf("."));
                                $('#doclist7').attr("href",contextPath+'/download?file='+data.doc7);
                                $('#doclist7name').html("&ensp;"+doc7name);
                                $('#doclist7').css("visibility",'visible');
                            }
                            if(data.doc8){
                                var doc8name = data.doc8.substring(data.doc8.lastIndexOf("/")+1,data.doc8.lastIndexOf("."))
                                $('#doclist8').attr("href",contextPath+'/download?file='+data.doc8);
                                $('#doclist8name').html("&ensp;"+doc8name);
                                $('#doclist8').css("visibility",'visible');
                            }

                            $('input[name="docname"]').attr("value",data.docname);
                            $('input[name="docnum"]').attr("value",data.docnum);
                            $('input[name="uploader"]').attr("value",data.uploader);
                            $('input[name="uploadtime"]').attr("value",data.uploadtime);
                            $('textarea[name="ycschick"]').val(data.ycschick);
                            $('input[name="txr"]').attr("value",data.txr);
                            $('input[name="txrtime"]').attr("value",data.txrtime);
                        },
                        yes: function(index) {
                            console.log(index);
                        },
                        full: function(elem) {
                            var win = window.top === window.self ? window : parent.window;
                            $(win).on('resize', function() {
                                var $this = $(this);
                                elem.width($this.width()).height($this.height()).css({
                                    top: 0,
                                    left: 0
                                });
                                elem.children('div.layui-layer-content').height($this.height() - 95);
                            });
                        }
                    });
                    form.render();
                });
            },
            error:function (e) {
            }
        });
    });

    $('body').on('click', '#close', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });

    exports('ConstDocList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});